package com.hy;

import java.util.LinkedList;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * author: Mr.Du
 * Date: 2023/5/31
 * Time: 22:12
 */
public class MaxQueue {
    
    // /单调递减的队列
    private LinkedList<Integer> list1;
    //包含所有数据的队列
    private LinkedList<Integer> list2;
    
    public MaxQueue() {
        list1 = new LinkedList<>();
        list2 = new LinkedList<>();
    }
    
    public int max_value() {
        if (list1.isEmpty()) {
            return -1;
        }
        return list1.getFirst();
    }
    
    public void push_back(int value) {
        list2.add(value);
        while (!list1.isEmpty() && list1.getLast() < value) {
            list1.removeLast();
        }
        list1.add(value);
    }
    
    public int pop_front() {
        if (list1.isEmpty()) {
            return -1;
        }
        int res = list2.removeFirst();
        if (list1.getFirst() == res) {
            list1.removeFirst();
        }
        return res;
    }
    
    
    public static void main(String[] args) {
    
    }
}

